﻿using System;
using BalanceManager.Services;
using Microsoft.Practices.Unity;

namespace BalanceManager.ViewModels
{
    public class ViewModelLocator : IDisposable
    {
        private bool disposed;
        private readonly ContainerService containerService;

        public ViewModelLocator()
        {
            this.containerService = new ContainerService();
        }

        public HistoryViewModel HistoryViewModel   
        {
            get { return containerService.Container.Resolve<HistoryViewModel>(); }
        }

        public ItemsViewModel ItemsViewModel
        {
            get { return containerService.Container.Resolve<ItemsViewModel>(); }
        }

        public AddFundFlowViewModel AddFundFlowViewModel
        {
            get { return containerService.Container.Resolve<AddFundFlowViewModel>(); }
        }

        public MainViewModel MainViewModel
        {
            get { return containerService.Container.Resolve<MainViewModel>(); }
        }

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                this.containerService.Dispose();
            }

            disposed = true;
        }
    }
}
